<?php
/**
 * Created by PhpStorm.
 * User: lyw
 * Date: 2016/5/25
 * Time: 10:13
 */

class Promotion_articlesController extends BaseController {
    public function index(){
        $doArticles = new Do推广文章();
        $doArticles->set_公众号ID(G_SERV_ID);
        $count = $doArticles->where($doArticles->data)->count();
        $page = new \tools\Page($count,15);
        $promotionArticles = $doArticles->where($doArticles->data)
            ->offset($page->limit)
            ->limit($page->pagesize)
            ->rows();
        require $this->template;
    }
    public function update(){
        $doArticles = new Do推广文章();
        $id = $this->request('id');
        $show = $this->request('show');
        $info = '添加成功';
        $false = '添加失败';
        if($id)
        {
            $doArticles->set_id($id);
            $promotionArticle = $doArticles->where($doArticles->data)->row();
            $info = '修改成功';
            $false = '修改失败';
        }
        if($show)
        {
            $doArticles->set_是否显示($show);
            $doArticles->save();
            $this->redirect('promotion_articles','index');
        }
        if($_POST)
        {
            $title = $this->request('title','',true);
            $remarks = $this->request('备注');
            $content = $this->request('content');
            $doArticles->set_公众号ID(G_SERV_ID);
            $doArticles->set_标题($title);
            $doArticles->set_备注($remarks);
            $doArticles->set_内容($content);
            $doArticles->set_公众号openID($_SESSION['公众号openID']);
            $result = $doArticles->save();
            if($result)
            {
                $url = $this->url('promotion_articles','index');
                $this->successPage($info,$url);
            }
            else{
                $this->successPage($false);
            }
        }
        require $this->template;
    }

    public function promotion_text(){
        $dos = new Do后台管理员();
        $id = $this->request('id');
        $content = $this->request('content');
        if($_POST)
        {
            $dos->set_id($id);
            $dos->set_分享介绍($content);
            $result = $dos->save();
            if($result)
            {
                $url = $this->url('promotion_articles','index');
                $this->successPage("修改成功",$url);
            }
            else
            {
                $this->successPage("修改失败");
            }
        }
        $dos->set_公众号ID(G_SERV_ID);
        $res = $dos->where($dos->data)->row();
        require $this->template;
    }

}